package com.t360.numberencoding;

import java.io.File;
import java.io.IOException;
import java.util.List;


public class Main 
{
    public static void main(String[] args) {
    	// Get the default mapping digits -> letters
        Mapping mapping = Mapping.getDefaultMapping();
        LineReader reader = null;
        
		try {
			// Read the whole dictionary
			if (args.length > 1) {
				reader = LineReader.fromFile(new File(args[1]));
			}
			else {
				reader = LineReader.fromFile(new File("default_dictionary.txt"));
			}
			
			reader.readAll();
		} catch (IOException e) {
			e.printStackTrace();
			return;
		}
		
        Dictionary dictionary = new Dictionary(reader.getLines());
        Combination combination = new Combination(dictionary, mapping);
        
        try {
	    	if (args.length > 0) {
	    		reader = LineReader.fromFile(new File(args[0]));
	    	}
	    	else {
	    		reader = LineReader.fromStdin();
	    	}
			
	        while (reader.ready()) {
	        	String number = reader.nextLine();
	        	List<String> associations = combination.getNumberAssociations(number);
	        	
	        	for (String association : associations) {
	        		System.out.println(association);
	        	}
	        }
		} catch (IOException e) {
			e.printStackTrace();
		}
    }
}
